<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
<c:if test="${mcTypeList==null && empty param.msg}">
	<c:redirect url="/servlet/McManageServlet?fromPage=/Admin/Admin_Mcadd.jsp"></c:redirect>
</c:if>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Shop 管理中心 - 添加新商品</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="<c:url value="/Admin/styles/general.css"/>" rel="stylesheet" type="text/css" />
	<link href="<c:url value="/Admin/styles/main.css"/>" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<c:url value='/js/user.js'/>"></script>
    <script language="javascript">
    <c:forEach var="mcTypeMap" items="${mcTypeList}">
    <c:forEach var="me" items="${mcTypeMap}">
        <c:set var="maxType" value="${me.key}" />
        <c:set var="minList" value="${me.value}"/>
    </c:forEach>
        var array_${maxType.nid}=new Array();
        <c:forEach var="minType" items="${minList}" varStatus="lStatus">
            array_${maxType.nid}[${lStatus.index}]="${minType.nid};${minType.sname}";
        </c:forEach>
    </c:forEach>

    function maxChange() {
        var maxtypeObj = document.getElementById("maxType");
        var mintypeObj = document.getElementById("minType");
        
        var maxtype_value = maxtypeObj.value;
        mintypeObj.options.length=0;
        if(maxtype_value!=""){
            mintypeObj.options.add(new Option("请选择....",""));
            document.forms['mcAdd'].elements['minType'].disabled = '';
            var arrayObj = eval("array_" + maxtype_value);
            for(i=0;i<arrayObj.length;i++) {
                var tmp_array=arrayObj[i].split(";");
                mintypeObj.options.add(new Option(tmp_array[1],tmp_array[0]));
            }
        } else {
            document.forms['mcAdd'].elements['minType'].disabled = 'disabled';
        }
    }
    
    function minChange() {
        maxChange();
        var mintypeObj = document.getElementById("minType");
        
        for(i=0;i<mintypeObj.options.length;i++) {
            if(mintypeObj.options[i].value=="${typeMin}") {
                mintypeObj.options[i].selected=true;
                break;
            }
        }
    }
	
	function uploadNoPic() {
	
		var nopic=document.getElementById('nopic');
		
		if(nopic.checked==false){
			document.getElementById('mcimg').disabled="";
			document.getElementById('flag').value="";
		} else if(nopic.checked==true) {
			document.getElementById('mcimg').disabled="disabled";
			document.getElementById('flag').value="nopic.gif";
		}
	}

	</script>
    <c:if test="${not empty param.msg}">
    	<script language="javascript">
			alert('${param.msg}');
			location="<c:url value="/Admin/Admin_Mcadd.jsp" />";
		</script>
    </c:if>

  </head>
  
  <body>
    <h1>
		<span class="action-span"><a href="<c:url value="/Admin/Admin_Mclist.jsp" />" >商品列表</a></span>
		<span><a href="Admin_Main.jsp">Shop 管理中心</a>  - 添加新商品 </span>
	</h1>
	<div class="main-div">
		<form method="post" action="<c:url value='/Admin/McAddServlet'/>" name="mcAdd"  enctype="multipart/form-data" onSubmit="return checkAdminAddMc();">
		<table width="100%" >
		  <tr>
		    <td class="label">商品名称:</td>
		    <td><input name="sname" type="text"/>
		    	<span id="mcname">(必填)</span></td>
		  </tr>
		  <tr>
		    <td class="label">商品大类:</td>
		    <td>
		        <select name="maxType" id="maxType" onChange="maxChange();" style="vertical-align:middle;width:147px;">
		        <option value="">请选择....</option>
		        <c:forEach var="mcTypeMap" items="${mcTypeList}">
		        <c:forEach var="me" items="${mcTypeMap}">
		        <c:set var="maxType" value="${me.key}" />
		        <c:choose>
		        <c:when test="${typeMax==maxType.nid}">
		            <option value="${maxType.nid}" selected="selected">${maxType.sname}</option>
		        </c:when>
		        <c:otherwise>
		            <option value="${maxType.nid}">${maxType.sname}</option>
		        </c:otherwise>
		        </c:choose>
		        </c:forEach>
		        </c:forEach>
		        </select>
		    </td>
		  </tr>
		  <tr>
		    <td class="label">商品小类:</td>
		    <td><select name="minType" id="minType" style="vertical-align:middle;width:147px;"></select></td>
		  </tr>
		  <tr>
		    <td class="label">商品单价:</td>
		    <td><input name="nprice" type="text"/>
		    <span id="mcprice">(必填)</span></td>
		  </tr>
		  <tr>
		    <td class="label">是否缺货:</td>
		    <td><input name="smctag" type="radio" value="0" checked="checked" />&nbsp;有货&nbsp;<input type="radio" name="smctag" value="1"/>&nbsp;缺货&nbsp;</td>
		  </tr>
		  <tr>
		    <td class="label">商品图片:</td>
		    <td>
		    	<input type="hidden" name="flag" id="flag" value="" />
		        <input type="file" name="mcimg" id="mcimg" title="图片格式只能是.jpg .gif .png .bmp" />
		        <input type="checkbox" name="nopic" id="nopic" onClick="uploadNoPic();" />
		        如不使用商品图片，请打钩!</td>
		  </tr>
		  <tr>
		    <td class="label">商品描述:</td>
		    <td><textarea name="sdescription" cols="30" rows="6"></textarea></td>
		  </tr>
		  <tr>
		  	<td align="right">
		  	  <input type="submit" value=" 添加 " class="button" />
		    </td>
		    <td align="left"><input type="reset" value=" 重置 " class="button" /></td>
		  </tr>
		</table>
		</form>
	</div>
	<div id="footer">版权所有 &copy;</div>
	<script language="javascript" >
	  <!--
	        var mcname_empty = "商品名称不能为空。";
			var mcprice_empty = "商品单价不能为空";
			var mcprice_msg = "商品价格只能为浮点数";
			var mcimg_msg = "图片格式错误.请重新选择商品图片.\n\n图片格式只能为 gif jpg png bmp";
			var Type_empty = "请选择商品类别";
			var mcimg_empty = "请选择商品图片文件\n\n或点击不使用商品图片"
		-->
	</script>
	<script type="text/javascript">
		window.onload = function()
		{
		  minChange();
		}
	</script>
  </body>
</html>
